<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="jca" uri="http://www.ptc.com/windchill/taglib/components"%>
<%@ include file="/netmarkets/jsp/components/beginWizard.jspf" %>
<%@ include file="/netmarkets/jsp/components/includeWizBean.jspf" %>
<%@ taglib uri="http://www.ptc.com/windchill/taglib/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()  + path + "/";
%>
<fmt:setBundle basename="ext.huaqin.generic.resource.BizObjectResource" />
<fmt:message var="HQ_CUSTOMER_SEACH" key="HQ_CUSTOMER_SEACH" />

<jca:wizard title="${HQ_CUSTOMER_SEACH}" buttonList="DefaultWizardButtonsNoApply">	
	<jca:wizardStep action="searchCustomerStep" type="bizObject" />
</jca:wizard> 

<head>
</head>

<script language="javascript">
	wizardSteps['bizObject.searchCustomerStep'].afterJS = function(wizardAction) {
		if("SUBMIT" == wizardAction ){
			
			var table = PTC.jca.table.Utils.getTable("ext.tianma.doc.SendOut.builder.SearchCustomerTableBuilder");
			var allSelection = table.getSelectionModel().getSelections();
			if(allSelection.length==0){
				JCAAlert('com.ptc.core.agreements.agreementsResource.NOTHING_SELECTED');
				return false;
			}
			var name = allSelection[0].get('supplierName');
			var supplierCode = allSelection[0].get('supplierCode');
			
			var contacts = window.opener.document.getElementById('contacts');//接口人
			
			Ext.Ajax.request({
				url: '/Windchill/netmarkets/jsp/document/contacts.jsp',
				params: {
					supplier:supplierCode
				},
				success: function(response){
					var supplierObj = window.opener.document.getElementById("supplier");
					//var supplierObj_hidden = window.opener.document.getElementById("supplier_hidden");
					if(supplierObj != null){
						var splitKey = " | ";//供应商之间的分割符
						if(supplierObj.value.length == 0) {
							supplierObj.value = name;
						} else {
							if(supplierObj.value.indexOf(name) > -1) {
								Ext.Msg.alert("提示","供应商【" + name + "】已存在，不能重复选择" );
								return false;
							} else {
								supplierObj.setValue(supplierObj.value + ",\n" + name );
							}
						}
					}

					//contacts.options.length = 0;
					if(null != response && null != response.responseText) {
						var contactInfo = Ext.util.JSON.decode(response.responseText);
						
						var historyLength = contacts.options.length;
						
						contacts.options.length = contacts.options.length + contactInfo.length;//与contacts.options[i].value=showUser;结合使用，重新赋值
						for(var i = 0; i < contactInfo.length; i++) {
							var con = contactInfo[i];
							var userName = con.userName;
							var fullName = con.fullName;
							var id = con.id;
							var email = con.email;
							var showUser = fullName + "(" + email + ")";
							//contacts.options.add(new Option(showUser, id));
							
							contacts.options[i+historyLength].value=id;
							contacts.options[i+historyLength].text=showUser;
						}
						contacts.style.width='407';
						window.close();
					}
				},
				failure : function() {
					Ext.Msg.alert("提示","此供应商未维护接口人，请先申请维护此供应商接口人信息");
				}
			});
		}
	}
</script>



<%@include file="/netmarkets/jsp/util/end.jspf"%>